package com.xpj.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.locks.LockSupport;

public class MyFutureTask3<V> implements Runnable{

    private Callable<V> callable;
    private V v;
    private Thread currentThread;

    public MyFutureTask3(Callable<V> callable){
        this.callable = callable;
    }

    @Override
    public void run() {

        try {
            this.v = callable.call();
        } catch (Exception e) {
            e.printStackTrace();
        }
        LockSupport.unpark(currentThread);

    }

    public V get(){
        this.currentThread = Thread.currentThread();
        LockSupport.park();
        return v;
    }
}
